#include "StdAfx.h"
#include "UIMemDC.h"


CUIMemDC::CUIMemDC( HDC hDC, const RECT& rcClip )
{
    m_hSrcDC = hDC;
//	::GetClipBox(hDC,&m_rcClip);
    ::CopyRect( &m_rcClip, &rcClip );

    m_hMemDC =::CreateCompatibleDC( hDC );
    m_hMemBitmap =::CreateCompatibleBitmap( hDC, rcClip.right - rcClip.left, rcClip.bottom - rcClip.top );
    m_hOldBitmap = ( HBITMAP )::SelectObject( m_hMemDC, m_hMemBitmap );
}

HDC CUIMemDC::GetDC()
{
    return m_hMemDC;
}

void CUIMemDC::DoPaint()
{
    ::BitBlt( m_hSrcDC, m_rcClip.left, m_rcClip.top, m_rcClip.right - m_rcClip.left, m_rcClip.bottom - m_rcClip.top, m_hMemDC, m_rcClip.left, m_rcClip.top, SRCCOPY );
    ::SelectObject( m_hMemDC, m_hOldBitmap );
    ::DeleteObject( m_hOldBitmap );
    ::DeleteObject( m_hMemBitmap );
    ::DeleteObject( m_hMemDC );
}

CUIMemDC::~CUIMemDC( void )
{
    DoPaint();
}
